package com.waiting.leetcode;

import java.util.LinkedList;
import java.util.List;

/**
 * @Description
 * @Author bjweitingting
 * @Date 2019/3/22
 **/
public class RotateString796 {
    public static void main(String[] args) {
        String A = "abcde", B = "abced";
        System.out.println(rotateString(A, B));
    }


    public static boolean rotateString(String A, String B) {
        if (A.equals(B)) {
            return true;
        } else if (A.isEmpty() || B.isEmpty()) {
            return false;
        }
        List<Integer> helper = new LinkedList<>();
        char tmp = B.charAt(0);
        for (int i = 0; i < A.length(); i++) {
            if (A.charAt(i) == tmp) {
                helper.add(Integer.valueOf(i));
            }
        }
        for (Integer item : helper) {
            StringBuilder sb = new StringBuilder();
            sb.append(A.substring(item));
            sb.append(A.substring(0, item));
            if (sb.toString().equals(B)) {
                return true;
            }
        }
        return false;
    }
}
